package com.sskj.cndragon.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.cndragon.bean.AssetListBean;
import com.sskj.cndragon.bean.IncomesBean;
import com.sskj.cndragon.bean.MyTeamListBean;
import com.sskj.cndragon.http.HttpConfig;
import com.sskj.cndragon.ui.activity.MySpreadActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;


public class MySpreadActivityPresenter extends BasePresenter<MySpreadActivity> {

    public void getIncomes(String userID) {
        httpService.getIncomes(userID)
                .tag(this)
                .execute(new JsonCallBack<HttpData<IncomesBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<IncomesBean>> response) {
                        HttpData body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.getIncomesOK((IncomesBean) body.getData());
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }
                    }
                });
    }

    public Flowable<List<MyTeamListBean.MyTeamBean>> getMyTeamRecord(int type, int page) {
        return httpService.getMyTeamRecord(SPUtil.get(SPConfig.ID,""),type,page)
                .tag(this)
                .converter(new JsonConverter<HttpData<MyTeamListBean>>() {
                })
                .adapt(new FlowableBody<>())
                .map(listHttpData -> listHttpData.getData().getList());
    }
}
